/*
 *
 * Copyright (C) 2012 Walter Lütgenau
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package offset.nodes.server.servlet.book.content;

import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;

/**
 * Used for filtering XML, implements an empty (non-filtering) filter.
 * Subclasses can focus on only the methods, that will really be overridden.
 * 
 * @author Walter L�tgenau
 */
public class EmptyFilterContentHandler implements ContentHandler {

    ContentHandler handler;
    boolean visible = true;

    /**
     * Gets the final content target.
     *
     * @param target
     */
    public EmptyFilterContentHandler(ContentHandler target) {
        if (visible)
            this.handler = target;
    }

    public void startPrefixMapping(String prefix, String uri) throws SAXException {
        if (visible)
            handler.startPrefixMapping(prefix, uri);
    }

    public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
        if (visible)
            handler.startElement(uri, localName, qName, atts);
    }

    public void startDocument() throws SAXException {
        if (visible)
            handler.startDocument();
    }

    public void skippedEntity(String name) throws SAXException {
        if (visible)
            handler.skippedEntity(name);
    }

    public void setDocumentLocator(Locator locator) {
        if (visible)
            handler.setDocumentLocator(locator);
    }

    public void processingInstruction(String target, String data) throws SAXException {
        if (visible)
            handler.processingInstruction(target, data);
    }

    public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
        if (visible)
            handler.ignorableWhitespace(ch, start, length);
    }

    public void endPrefixMapping(String prefix) throws SAXException {
        if (visible)
            handler.endPrefixMapping(prefix);
    }

    public void endElement(String uri, String localName, String qName) throws SAXException {
        if (visible)
            handler.endElement(uri, localName, qName);
    }

    public void endDocument() throws SAXException {
        if (visible)
            handler.endDocument();
    }

    public void characters(char[] ch, int start, int length) throws SAXException {
        if (visible)
            handler.characters(ch, start, length);
    }

    protected String getName(String uri, String localName, String qName) {
        return qName;
    }

    public ContentHandler getHandler() {
        return handler;
    }

    public boolean isVisible() {
        return visible;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }
}
